<template>
  <div class="achievements-details">
    <div class="nav-list max-wrapper">
      <div class="nav-item" @click="router.push('/')">首页</div>
      /
      <div class="nav-item" @click="router.push('/expert-achievements')">成果库</div>
      /
      <div class="nav-item">成果详情</div>
    </div>
    <div class="achievements-main max-wrapper">
      <div class="main-l">
        <div class="info common-wrapper">
          <div class="title-header">
            <div class="title">
              <!-- 标题 -->
              <span v-if="route.query.code == 'CCND' || route.query.code == 'CJFD' || route.query.code == 'CDFD' || route.query.code == 'CMFD'">{{ detailsData.title }}</span>

              <span v-if="route.query.code == 'CPFD' || route.query.code == 'IPFD'">{{ detailsData.meettingName }}</span>

              <span v-if="route.query.code == 'SCPD'">{{ detailsData.patentTitle }}</span>
              

              <!-- 类型 -->
              <div class="type" v-if="route.query.code == 'CCND'">
                {{ detailsData.chineseNewspaperName }}
              </div>

              <div class="type" v-if="route.query.code == 'CDFD' || route.query.code == 'CJFD'">
                {{ detailsData.chineseJournalName }}
              </div>

              <div class="type" v-if="route.query.code == 'CMFD'">
                {{ detailsData.disciplineMajor }}
              </div>

              <div class="type" v-if="route.query.code == 'SCPD'">
                {{ detailsData.type }}
              </div>
            </div>
            <!-- <div class="button-group">
              <div class="button-item">
                阅读全文
              </div>
              <div class="button-item">
                下载
              </div>
              <div class="button-item">
                导出
              </div>
              <div class="button-item">
                分享
              </div>
            </div> -->
          </div>

          <!-- 字段 -->
          <el-row v-for="(fieldItem, fieldIndex) in showFields" :key="fieldIndex" :gutter="20">
            <el-col :span="4">
              <div class="item-label">{{ fieldItem.label }}：</div>
            </el-col>
            <el-col :span="20">
              <div class="item-value">{{ detailsData[fieldItem.key] }}</div>
            </el-col>
          </el-row>
          <div class="info-footer">
            被引：<span class="mark">{{ detailsData.citedFrequency ?? 0 }}</span>
            <!-- 本库浏览：<span class="mark">6</span> -->
            <div class="date">发布时间：{{ format(detailsData.pubDate) }}</div>
          </div>
        </div>

        <!-- 关键词 -->
        <div v-if="route.query.code == 'CDFD' || route.query.code == 'CJFD' || route.query.code == 'CMFD' || route.query.code == 'CPFD' || route.query.code == 'IPFD' || route.query.code == 'SCPD'"  class="keyword common-wrapper">
          <div class="common-title">关键词</div>
          <div class="keyword-list">
            <div v-for="(kitem, kindex) in keyWordsList" :key="kindex" class="keyword-item"> {{ kitem }}</div>
          </div>
        </div>

        <!-- 摘要 -->
        <div v-if="route.query.code == 'CDFD' || route.query.code == 'CJFD' || route.query.code == 'CMFD' " class="abstract common-wrapper">
          <div class="common-title">摘要</div>
          <div class="content">{{ detailsData.chineseAbstract }}</div>
        </div>
        <div v-if="route.query.code == 'CPFD' || route.query.code == 'IPFD'" class="abstract common-wrapper">
          <div class="common-title">摘要</div>
          <div class="content">{{ detailsData.paperAbstract }}</div>
        </div>
        <div v-if="route.query.code == 'SCPD'" class="abstract common-wrapper">
          <div class="common-title">摘要</div>
          <div class="content">{{ detailsData.abstract }}</div>
        </div>
      </div>

      <div class="main-r">
        <div class="r-header">相关推荐</div>
        <div class="ab-list">
          <el-scrollbar view-style="padding: 0 31px;" height="100%">
            <div @click="toRecod(item)" v-for="(item, index) in recommendList" :key="index" class="ab-item">
              <div class="ab-title">

                <!-- 类型 -->
                <span class="type" v-if="route.query.code == 'CCND'">[{{ item.chineseNewspaperName }}]</span>
                <span class="type" v-if="route.query.code == 'CDFD' || route.query.code == 'CJFD'">[{{ item.chineseJournalName }}]</span>
                <span class="type" v-if="route.query.code == 'CMFD'">[{{ item.disciplineMajor }}]</span>


                <!-- 标题 -->

                <span v-if="route.query.code == 'CCND' || route.query.code == 'CJFD' || route.query.code == 'CDFD' || route.query.code == 'CMFD'">{{ item.title }}</span>

                <span v-if="route.query.code == 'CPFD' || route.query.code == 'IPFD'">{{ item.meettingName }}</span>

                <span v-if="route.query.code == 'SCPD'">{{ item.patentTitle }}</span>
              </div>
              <div class="ab-footer">
                <span class="name otw-1">{{ item.author }}</span>
                <span class="date">{{ format(item.pubDate) }}</span>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default { name: 'AchievementsDetails' }
</script>
<script setup>
import { computed, ref } from 'vue';
import { useSystemStore } from '@/stores/modules/system.js';
import { http } from '@/utils/http/index.js'
import { useRoute, useRouter } from 'vue-router';
import { format } from '@/plugins/moment.js'
import { useAuthStore } from '@/stores/modules/auth.js';

const router = useRouter()
const route = useRoute()
const systemStore = useSystemStore()
const authStore = useAuthStore()

/**设置头部 */
systemStore.headerType = 'platform_black'
systemStore.headerBgcolor = 'normal'
systemStore.headerFontColor = '0'
systemStore.headerWidthType = 'max'
systemStore.needFooter = false
if (!route.query.id || !route.query.code) router.push('/')

const showFields = computed(() => {
  if (route.query.code == 'CCND') return [
    { key: 'theme', label: '主题' },
    { key: 'author', label: '作者' },
    { key: 'authorAffiliation', label: '作者单位' },
    { key: 'chineseNewspaperName', label: '来源' },
  ]
  if (route.query.code == 'CDFD') return [
    { key: 'author', label: '作者' },
    { key: 'authorAffiliation', label: '学位授予单位' },
    { key: 'thesisLevel', label: '论文级别' },
    { key: 'disciplineMajor', label: '学科专业名称' },
    { key: 'theme', label: '主题' },
    { key: 'chineseJournalName', label: '来源' },
  ]
  if (route.query.code=='CJFD') return [
    { key: 'author', label: '作者' },
    { key: 'theme', label: '主题' },
    { key: 'organization', label: '机构' },
    { key: 'publishingUnit', label: '来源' },
  ]
  if (route.query.code=='CMFD') return [
    { key: 'author', label: '作者' },
    { key: 'theme', label: '主题' },
    { key: 'publishingUnit', label: '机构' },
  ]
  if (route.query.code=='CPFD') return [
    { key: 'author', label: '作者' },
    { key: 'theme', label: '主题' },
    { key: 'authorAffiliation', label: '作者机构' },
    { key: 'meettingAddress', label: '会议地点' },
    { key: 'organizingInstitution', label: '会议类型' },
  ]
  if (route.query.code=='IPFD') return [
    { key: 'author', label: '作者' },
    { key: 'theme', label: '主题' },
    { key: 'authorAffiliation', label: '作者机构' },
    { key: 'meettingAddress', label: '会议地点' },
    { key: 'organizingInstitution', label: '会议类型' },
  ]
  if (route.query.code=='SCPD') return [
    { key: 'inventor', label: '发明者' },
    { key: 'author', label: '发明者机构' },
    { key: 'theme', label: '主题' },
    { key: 'source', label: '来源' },
    { key: 'patentAgency', label: '专利说明' },
  ]
  return []
})

const keyWordsList = ref([])

const detailsData = ref({})
http.$GET('/Achievements/GetAchievementsDetail', { AchievementsCode: route.query.code, uid: route.query.id }).then(res => {
  if (res.isError) return
  detailsData.value = res.result

  if(route.query.code == 'CDFD' || route.query.code == 'CJFD' || route.query.code == 'CMFD') {
    keyWordsList.value = res.result.chineseKeywords ? res.result.chineseKeywords.split(";;") : []
  }

  if(route.query.code == 'CPFD' || route.query.code == 'IPFD') {
    keyWordsList.value = res.result.paperKeyWords ? res.result.paperKeyWords.split(";;") : []
  }

  if(route.query.code == 'SCPD') {
    keyWordsList.value = res.result.keyWords ? res.result.keyWords.split(";;") : []
  }
  
})


const recommendList = ref([])
http.$POST('/Achievements/GetAchievementsList', {
  achievementsCodeArr: [route.query.code], theoryStudyGetListAndPageInfoInput: {
    pageIndex: 1,
    pageSize: 10,
    authToken: authStore.auth_token,
    orderbyCol: "Year",
    dfi: {
      logic: 0,
      filters: [
        { field: 'uniqueId', operator: 9, value: route.query.id }
      ]
    }
  }
}).then(res => {
  if (res.isError) return
  recommendList.value = res.result.dataLst
})

const toRecod = (item) => {
  window.open(`/expert-achievements/achievements-details?id=${item.uniqueId}&code=${item.tableName}`)
}

</script>

<style lang='scss' scoped>
.achievements-details {
  background-color: #F8F8F8;
  padding-top: 22px;
  padding-bottom: 60px;
  min-height: 100vh;
  font-family: PingFang SC-Medium, PingFang SC;

  .nav-list {
    display: flex;
    color: #999999;
    gap: 6px;
    margin-bottom: 20px;

    .nav-item {
      font-size: 16px;
      font-weight: 500;
      cursor: pointer;

      &:last-child {
        cursor: default;
        color: var(--theme-color);
      }
    }
  }

  .achievements-main {
    display: flex;
    gap: 19px;

    .common-title {
      font-size: 22px;
      font-weight: bold;
      color: #333333;
    }

    .main-l {
      flex: 1;
      width: 0;

      .common-wrapper {
        padding: 26px;
        background-color: #fff;
      }

      .info {
        margin-bottom: 15px;
        font-size: 18px;

        .title-header {
          padding-bottom: 23px;
          margin-bottom: 17px;
          border-bottom: 1px solid #F8F8F8;
          font-size: 22px;
          font-weight: 500;
          color: #333333;
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 20px;

          .title {
            display: flex;
            align-items: center;
            font-weight: bold;

            .type {
              padding: 3px 6px;
              border: 1px solid var(--theme-color);
              color: var(--theme-color);
              border-radius: 5px;
              font-size: 14px;
              margin-left: 10px;
            }
          }

          .button-group {
            margin-left: auto;
            display: flex;
            gap: 12px;

            .button-item {
              cursor: pointer;
              font-size: 16px;
              font-weight: 400;
              color: #4D4D4D;
              padding: 4px 6px;
              border-radius: 4px;
              border: 1px solid #4D4D4D;
            }
          }
        }

        .item-label {
          margin-bottom: 12px;
          text-align: right;
          color: #7C7C7C;
        }

        .item-value {
          color: #000;
        }

        .info-footer {
          margin-top: 22px;
          display: flex;
          color: #7C7C7C;
          font-size: 14px;

          .mark {
            color: var(--theme-color);
            margin-right: 6px;
          }

          .date {
            margin-left: auto;
            font-size: 14px;
            font-weight: 500;
            color: #414141;
          }
        }
      }

      .keyword {
        margin-bottom: 15px;
        background-color: #fff;

        .keyword-list {
          display: flex;
          margin-top: 18px;
          gap: 16px;
          padding-left: 15px;
          flex-wrap: wrap;

          .keyword-item {
            border: 1px solid var(--theme-color);
            color: var(--theme-color);
            padding: 4px 10px;
            border-radius: 4px;
          }
        }
      }

      .abstract {
        .content {
          text-indent: 2em;
          margin-top: 18px;
          font-size: 18px;
          font-weight: 400;
          line-height: 26px;
          min-height: 315px;
          text-align: justify;
          font-family: '宋体';
          letter-spacing: 1px;
        }
      }
    }

    .main-r {
      width: 400px;
      background-color: #fff;
      height: 794px;
      padding: 26px 0;
      display: flex;
      flex-direction: column;

      .r-header {
        padding: 0 31px;
        font-size: 22px;
        font-weight: bold;
        padding-bottom: 22px;
        border-bottom: 2px solid #F8F8F8;
        margin-bottom: 17px;
      }

      .ab-list {
        flex: 1;
        height: 0;

        .ab-item {
          cursor: pointer;
          margin-bottom: 22px;
          padding-bottom: 13px;
          border-bottom: 2px solid #F8F8F8;

          .ab-title {
            font-size: 16px;
            color: #333;
            margin-bottom: 10px;

            span.type {
              color: var(--theme-color);
            }
          }

          .ab-footer {
            display: flex;
            font-size: 14px;
            color: #7C7C7C;

            .name {
              color: #597BBC;
              margin-right: 6px;
              width: 70%;
            }

            .date {
              margin-left: auto;
            }
          }
        }
      }
    }
  }
}
</style>